module.exports = ( options, app) => {
    return async function errorHandler( ctx, next) {
        try {
            await next()
        } catch (error) {
            ctx.app.emit('error', error, ctx);
            const status = error.status || 500;  
            ctx.body = {
                code: status,
                data: null,
                message: error.message
            };
            ctx.status = status;
        }
    }
}